<?php
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
$this->context->layout=false;

?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>

<div style="margin:15px;">
<?php 
if (1){}else{}
	$form = ActiveForm::begin([
		'id' => 'm-form',
		"action" => Url::to(['export']),
        'options' => [
        	'class' => 'form-horizontal'
        ]
    ]);
?>
<table class="table">

	<tr>
		<th width="30%">
			姓名：
		</th>
		<td width="70%">
			<input type="text" name="name_cn_long"  class="k-input k-textbox" style="width:100%">
		</td>
	</tr>

	<tr>
		<th width="30%">
			部门名称：
		</th>
		<td width="70%">
			<select id="department" name="department_id[]" multiple data-placeholder="请选择部门...">
		</td>
	</tr>

	<tr>
		<th width="30%">
			职位：
		</th>
		<td width="70%">
			<select id="position" name="position_id[]" multiple data-placeholder="请选择职位...">
		</td>
	</tr>

	<tr>
		<th width="30%">
			入职日期：
		</th>
		<td width="70%">
			<input type="text" id="start-date" name="start_date" style="width:49%;float:left;">
			<input type="text" id="end-date" name="end_date" style="width:49%;float:left;">
		</td>
	</tr>

	<tr>
		<th width="30%">
			在职状态：
		</th>
		<td width="70%">
			<select id="position_status" name="position_status_id[]" multiple data-placeholder="请选择状态...">
		</td>
	</tr>

	<tr>
		<th width="30%">
			出生日月：
		</th>
		<td width="70%">
			<input type="text" id="start-dob-date" name="start_dob" style="width:100%;">

		</td>
	</tr>

	<tr>
		<th width="30%">
			实习期：
		</th>
		<td width="70%">
			<input type="text" id="start-internship-date" name="start_internship" style="width:49%;float:left;">
			<input type="text" id="end-internship-date" name="end_internship" style="width:49%;float:left;">
		</td>
	</tr>

	<tr>
		<th width="30%">
			离职日期：
		</th>
		<td width="70%">
			<input type="text" id="start-terminated-date" name="start_terminated" style="width:49%;float:left;">
			<input type="text" id="end-terminated-date" name="end_terminated" style="width:49%;float:left;">
		</td>
	</tr>


</table>
<a type="button" class="k-button k-button-icontext" id="m-submit-export" href="javascript:;" style="margin-top:20px;float:right;"><i class="glyphicon glyphicon-plus"></i>导出</a>

<?php ActiveForm::end(); ?>
</div>
<script>
	$(function(){

		$("#m-submit-export").click(function(){
			var _this = $(this);

			var _start = $("#start-date").val();
			var _end = $("#end-date").val();
           if(get_unix_time(_end)<get_unix_time(_start)){
           	layer.msg("日期区间不正确", {icon: 5});
			return;
		} 
			_this.parents("form").submit();
		})

		$("#start-date").kendoDatePicker({
	    	format:"MM/dd/yyyy"
	    });

		$("#end-date").kendoDatePicker({
	    	format:"MM/dd/yyyy"
	    });

	    $("#department").kendoMultiSelect({
	        dataTextField: "text",
	        dataValueField: "value",
	        dataSource: new kendo.data.DataSource({
	        	transport: {
	        		read:{
	        			url:"<?=Url::toRoute(['/hr/unit/default/getselectall']); ?>",
	        			dataType:"json"
	        		}
	        	}
	        }),
	       autoClose: false,
	       change:departmentChange
    	})

    	$("#position").kendoMultiSelect({
    		dataTextField: "text",
	        dataValueField: "value",
	        autoClose: false
    	});

		$("#position_status").kendoMultiSelect({
			dataTextField: "text",
			dataValueField: "value",
			dataSource:JSON.parse('<?=json_encode(\app\data\StaffData::getPositionStatus()) ?>'),
			autoClose: false
		});

		$("#start-dob-date").kendoDatePicker({
			format:"MM",
			depth:"year",
			start:"year"
		});
		$("#start-terminated-date").kendoDatePicker({
			format:"MM/dd/yyyy"
		});

		$("#end-terminated-date").kendoDatePicker({
			format:"MM/dd/yyyy"
		});

		$("#start-internship-date").kendoDatePicker({
			format:"MM/dd/yyyy"
		});

		$("#end-internship-date").kendoDatePicker({
			format:"MM/dd/yyyy"
		});

    	// $("#position").kendoMultiSelect({
	    //     dataTextField: "text",
	    //     dataValueField: "value",
	    //     dataSource: new kendo.data.DataSource({
	    //     	transport: {
	    //     		read:{
	    //     			url:"<?=Url::toRoute(['/hr/position/default/getselectall']); ?>",
	    //     			dataType:"json"
	    //     		}
	    //     	}
	    //     }),
	    //    autoClose: false
    	// })
	})


	function departmentChange(e){
		var arrId = $("#department").data("kendoMultiSelect").value();

		var position = $("#position").data("kendoMultiSelect");

		$.ajax({
			url:"<?=Url::toRoute(['/hr/position/default/getselectallbyunitid']); ?>",
			dataType:"json",
			data:{unit_id:arrId},
			success:function(d){
				position.dataSource.data(d);
			}
		})
	}
	function get_unix_time(dateStr)
	{
	    var newstr = dateStr.replace(/-/g,'/'); 
	    var date =  new Date(newstr); 
	    var time_str = date.getTime().toString();
	    return time_str.substr(0, 10);
	}



</script>